package view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.Button;
/**
 * 自定义控件，进度的按钮
 * @author Anson-pc
 *
 */
public class ProgressButton extends Button {
	
	private long mMax = 100;
	private long mProgress;
	private boolean isProgressEnable = true;
	
	
	
	/**
	 * 设置进度的最大值
	 * @return
	 */
	public long getmMax() {
		return mMax;
	}

	public void setmMax(long mMax) {
		this.mMax = mMax;
	}

	public long getmProgress() {
		return mProgress;
	}

	/**
	 * 设置当前进度
	 * @param mProgress
	 */
	public void setmProgress(long mProgress) {
		this.mProgress = mProgress;
		//重绘操作
		invalidate();
	}

	public boolean isProgressEnable() {
		return isProgressEnable;
	}

	/**
	 * 设置是否允许进度
	 * @param isProgressEnable
	 */
	public void setProgressEnable(boolean isProgressEnable) {
		this.isProgressEnable = isProgressEnable;
	}

	public ProgressButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public ProgressButton(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	//onlayout ondraw onmeasure
	
	@Override
	protected void onDraw(Canvas canvas) {
//		canvas.drawText("哈哈", 0, 0, getPaint());
		if (isProgressEnable) {
			Drawable bg = new ColorDrawable(Color.BLUE);
			int left =0;
			int top =0;
			int right = (int) (mProgress*1.0f/mMax * getMeasuredWidth()+.5f);
			int bottom = getBottom();
			bg.setBounds(left, top, right, bottom);
			bg.draw(canvas);
		}
		
		
		
		super.onDraw(canvas);
	}

}
